#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
class Solution {
public:
    string solve(string IP)
    {
        int flag = 1;
        if (IP.find(':') != string::npos)
        {
            flag = 2;
        }
        if (flag == 1) IP.push_back('.');
        else if (flag == 2) IP.push_back(':');
        cerr << "IP=" << IP << endl;

        int count = 0;
        int countC = 0;
        string tmp;
        for (int i = 0;i < IP.size();++i)
        {
            if (IP[i] == '.')
            {
                //if(tmp.empty()) continue; 
                if (tmp[0] == '0')
                    return "Neither";
                ++count;
                if (!tmp.empty()) ++countC;
                int num = strtol(tmp.c_str(), nullptr, 10);
                if (num < 0 || num>255)
                {
                    return "Neither";
                }
                tmp.resize(0);
            }
            else if (IP[i] == ':')
            {
                if (tmp.size() > 4)
                    return "Neither";
                //if(tmp.empty()) continue; 
                ++count;
                if (!tmp.empty()) ++countC;
                int num = strtol(tmp.c_str(), nullptr, 16);
                if (num < 0 || num>65535)
                {
                    return "Neither";
                }
                tmp.resize(0);
            }
            else
            {
                if (flag == 2 && ((IP[i] >= 'G' && IP[i] <= 'Z') || (IP[i] >= 'g' && IP[i] <= 'z')))
                    return "Neither";
                if (flag == 1 && (IP[i] < '0' || IP[i]>'9'))
                    return "Neither";
                tmp += IP[i];
            }
        }
        cerr << "count=" << count << endl;
        if (flag == 1)
        {
            if (count != 4 || countC != 4) return "Neither";
            cerr << "IPv4" << endl;
            return "IPv4";
        }
        if (count != 8 || countC != 8) return "Neither";
        cerr << "IPv6" << endl;
        return "IPv6";
    }
};